import sys
import csv
import math

def calculateMean(sum, count):
    return sum / float(count)
    
def calculateVariance(sum, sqr_sum, count):
    return (sqr_sum / float(count - 1)) - ((sum*sum) / (count * float(count - 1)))

def calculateStandardDeviation(variance):
    return math.sqrt(variance)
    
file_name = sys.argv[1]
file = open(file_name)
reader = csv.DictReader(file)

red_sum = 0
red_sqr_sum = 0

green_sum = 0
green_sqr_sum = 0

blue_sum = 0
blue_sqr_sum = 0

count = 0

result = []

index = 0

for row in reader:
    if row['Cap'] == str(index):
        red = int(row['Red'])
        green = int(row['Green'])
        blue = int(row['Blue'])
    
        red_sum += red
        red_sqr_sum += (red * red)
        
        green_sum += green
        green_sqr_sum += (green * green)
        
        blue_sum += blue
        blue_sqr_sum += (blue * blue)
        
        count += 1
    else:
        result.insert(index, {})
    
        result[index]['Red'] = (calculateMean(red_sum, count), calculateVariance(red_sum, red_sqr_sum, count), calculateStandardDeviation(calculateVariance(red_sum, red_sqr_sum, count)))
        result[index]['Green'] = (calculateMean(green_sum, count), calculateVariance(green_sum, green_sqr_sum, count), calculateStandardDeviation(calculateVariance(green_sum, green_sqr_sum, count)))
        result[index]['Blue'] = (calculateMean(blue_sum, count), calculateVariance(blue_sum, blue_sqr_sum, count), calculateStandardDeviation(calculateVariance(blue_sum, blue_sqr_sum, count)))
    
        red = int(row['Red'])
        green = int(row['Green'])
        blue = int(row['Blue'])
    
        red_sum = red
        red_sqr_sum = (red * red)
        
        green_sum = green
        green_sqr_sum = (green * green)
        
        blue_sum = blue
        blue_sqr_sum = (blue * blue)
        
        count = 1
        index = int(row['Cap'])

result.insert(index, {})
    
result[index]['Red'] = (calculateMean(red_sum, count), calculateVariance(red_sum, red_sqr_sum, count), calculateStandardDeviation(calculateVariance(red_sum, red_sqr_sum, count)))
result[index]['Green'] = (calculateMean(green_sum, count), calculateVariance(green_sum, green_sqr_sum, count), calculateStandardDeviation(calculateVariance(green_sum, green_sqr_sum, count)))
result[index]['Blue'] = (calculateMean(blue_sum, count), calculateVariance(blue_sum, blue_sqr_sum, count), calculateStandardDeviation(calculateVariance(blue_sum, blue_sqr_sum, count)))
               
for i in xrange(len(result)):
    print i,
    print '->',
    print result[i]['Red'][0],
    print result[i]['Green'][0],
    print result[i]['Blue'][0],
    print result[i]['Red'][1],
    print result[i]['Green'][1],
    print result[i]['Blue'][1],
    print result[i]['Red'][2],
    print result[i]['Green'][2],
    print result[i]['Blue'][2]